﻿/*
* This software is the confidential and proprietary
* information of NetBay
* Such confidential information should not be disclosed
* NetBay copyright(c) 2011
*/
#region
using System;
using System.Collections.Generic;
using NetBay.Core.BusinessEntities;
using System.Data;
using NetBay.Core.BusinessEntities.Enum;
using NetBay.Core.Extensions;

#endregion

namespace Rio.Manager.Business.Repository.Translator
{
    public class GeneralParameterTranslator
    {
        /// <summary>
        /// Gets all general parameters.
        /// </summary>
        /// <returns></returns>
        public static List<GeneralParameter> GetAllGeneralParameters(IDataReader P_oDbDataReader)
        {
            List<GeneralParameter> parameters = new List<GeneralParameter>();

            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        GeneralParameter param = new GeneralParameter();
                        param.Identifier = Convert.ToInt32(P_oDbDataReader["RP_GE_ID"].ToString());
                        param.Domain = (GeneralParameterDomain)EnumEx.eGetEnumValueFromDescription(typeof(GeneralParameterDomain), P_oDbDataReader["RP_GE_DOMAINE"].ToString()); 
                        param.Name = P_oDbDataReader["RP_GE_NOM"].ToString();
                        param.Description = P_oDbDataReader["RP_GE_DESCRIPTION"].ToString();
                        param.Value = P_oDbDataReader["RP_GE_VALEUR"].ToString();
                        param.EnumName = (GeneralParameterName)EnumEx.eGetEnumValueFromDescription(typeof(GeneralParameterName), P_oDbDataReader["RP_GE_NOM"].ToString()); 
                        param.IsEnabled = true;
                        param.IsMandatory = true;
                        parameters.Add(param);
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("EXCEPTION -> " + Environment.NewLine + ex);
            }
            return parameters;
        }

        /// <summary>
        /// Gets the general parameter.
        /// </summary>
        /// <returns></returns>
        public static GeneralParameter GetGeneralParameter(IDataReader P_oDbDataReader)
        {
            GeneralParameter param = new GeneralParameter();
            try
            {
                using (P_oDbDataReader)
                {
                    if (P_oDbDataReader.Read())
                    {
                        param.Identifier = Convert.ToInt32(P_oDbDataReader["RP_GE_ID"].ToString());
                        param.Domain = (GeneralParameterDomain)EnumEx.eGetEnumValueFromDescription(typeof(GeneralParameterDomain), P_oDbDataReader["RP_GE_DOMAINE"].ToString()); 
                        param.Name = P_oDbDataReader["RP_GE_NOM"].ToString();
                        param.Description = P_oDbDataReader["RP_GE_DESCRIPTION"].ToString();
                        param.Value = P_oDbDataReader["RP_GE_VALEUR"].ToString();
                        param.EnumName = (GeneralParameterName)EnumEx.eGetEnumValueFromDescription(typeof(GeneralParameterName), P_oDbDataReader["RP_GE_NOM"].ToString()); 
                        param.IsEnabled = true;
                        param.IsMandatory = true;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("EXCEPTION -> " + Environment.NewLine + ex);
            }
            return param;
        }
    }
}